Page({
  data: {
    needOpen: false,
    billType: 'person',
    billCont: 'detail',
    isRuleTipShowed: false,
    nick:'',
    phone:'',
    email:'',
    company_name:'',
    code:'',
    isCodeTipShowed: false
  },
  onShow() {
    this.setData({
      needOpen:false,
      billType:'person'
    });
  },
  onTypeSelect(e){
    //console.log('onTypeSelect:',e);
    if(e.detail.title=='发票'){
      this.setData({needOpen:e.detail.type=='type2'});
    }
    if(e.detail.title=='发票抬头'){
      this.setData({billType:e.detail.type=='type1'?'person':'company'});
    }
    if(e.detail.title=='发票内容'){
      this.setData({billType:e.detail.type=='type1'?'detail':'category'});
    }
    //
  },
  showRuleTip(e) {
    this.setData({isRuleTipShowed:true});
  },
  hideRuleTip(e){
    this.setData({isRuleTipShowed:false});
  },
  showCodeTip(e) {
    this.setData({isCodeTipShowed:true});
  },
  hideCodeTip(e){
    this.setData({isCodeTipShowed:false});
  },
  onConfirm(e){
    if(!this.data.needOpen){
      //wx.setStorageSync('opened_bill',0);
      wx.navigateTo({url: '../index?opened_bill=0',});
      return;
    }
    if(this.data.billType=='person'){
      if(this.data.nick.length<2){
        wx.showToast({title: '请正确填写姓名',});
        return;
      }
      if(this.data.phone.length!=11){
        wx.showToast({title: '请正确填写手机号码',});
        return;
      }
    }else{
      if(this.data.company_name.length<2){
        wx.showToast({title: '请正确填写公司名称',});
        return;
      }
      if(this.data.code.length<15){
        wx.showToast({title: '请正确填写纳税人识别号',});
        return;
      }
    }
    if(this.data.email.length<5 || this.data.email.indexOf('@')==-1){
      wx.showToast({title: '请正确填写邮箱地址',});
      return;
    }
    //wx.setStorageSync('opened_bill',1);
    wx.navigateTo({ url: '../index?opened_bill=1',});
  },
  onInputChange(e) {
    let lab=e.currentTarget.dataset.label;
    let value=e.detail;
    if(lab=='姓名')this.setData({nick:value});
    if(lab=='手机')this.setData({phone:value});
    if(lab=='邮箱')this.setData({email:value});
    if(lab=='公司名称')this.setData({company_name:value});
    if(lab=='识别号')this.setData({code:value});
  }
})